package com.mybatis.core.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;

/**
 * 使用@EnableTransactionManagement注解，开启事务管理
 *
 * @author xieshue
 * @date 2017\11\15 0015
 */
@Configuration
@EnableTransactionManagement
public class TransactionConfig/* implements TransactionManagementConfigurer*/ {

//    @Bean
//    public PlatformTransactionManager transactionManager(DataSource druidDataSource) {
//        return new DataSourceTransactionManager(druidDataSource);
//    }

    @Bean
    public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }
}
